//: Playground - noun: a place where people can play

import UIKit

/*
 2017年06月13日14:51:42
 如何将不相关的类型放到同一个容器类型中?
 使用enum将类型包装后再放入容器中
 */
class Person {
    var name = "xiaoming"
}

enum Box {
    case int(Int)
    case string(String)
    case object(Person)
}

let foo = [
    Box.int(5),
    Box.string("hello"),
    Box.object(Person())
]

foo.forEach {
    switch $0 {
    case .int(let i):
        print(i)
    case .string(let s):
        print(s)
    case .object(let o):
        print(o.name)
    }
}


/*
 tips: optional的结构体其实就是enum
 */
var bar: String? = "had"

switch bar {
case .some(let b):
    print(b)
case .none:
    print("nil")
}